/*******************************************************************************
* Copyright (C) 2019 China Micro Semiconductor Limited Company. All Rights Reserved.
*
* This software is owned and published by:
* CMS LLC, No 2609-10, Taurus Plaza, TaoyuanRoad, NanshanDistrict, Shenzhen, China.
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with CMS
* components. This software is licensed by CMS to be adapted only
* for use in systems utilizing CMS components. CMS shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. CMS is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/


/****************************************************************************/
/** \file isr.c
**
**	History:
**	
*****************************************************************************/
/****************************************************************************/
/*	include files
*****************************************************************************/

#include "main.h"

/****************************************************************************/
/*	Local pre-processor symbols/macros('#define')
*****************************************************************************/
/****************************************************************************/
/*	Global variable definitions(declared in header file with 'extern')
*****************************************************************************/
extern unsigned char Sys1msFlag;
extern unsigned char Sys10msFlag;

void NMI_Handler(void)
{
	
}
/****************************************************************************
 ** \brief	HardFault_Handler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void HardFault_Handler(void)
{
	
}

/****************************************************************************
 ** \brief	SVC_Handler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void SVC_Handler(void)
{
	
}

/****************************************************************************
 ** \brief	PendSV_Handler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void PendSV_Handler(void)
{
	
}
/****************************************************************************
 ** \brief	SysTick_Handler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void SysTick_Handler(void)
{
    static uint8_t cnt10ms = 0;
	
	Sys1msFlag = 1;	
	if(++cnt10ms >= 10)
	{
		Sys10msFlag = 1;
		cnt10ms = 0;
	}
}
           
/****************************************************************************
 ** \brief	GPIO0_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void GPIO0_IRQHandler(void)
{
	if(GPIO_GetIntFlag(GPIO0,GPIO_PIN_1))
	{		
		GPIO_ClearIntFlag(GPIO0,GPIO_PIN_1);
	}	
}

/****************************************************************************
 ** \brief	GPIO1_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void GPIO1_IRQHandler(void)
{
	if(GPIO_GetIntFlag(GPIO1,GPIO_PIN_5))
	{		
		GPIO_ClearIntFlag(GPIO1,GPIO_PIN_5);
	}		
}
/****************************************************************************
 ** \brief	GPIO2_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void GPIO2_IRQHandler(void)
{
	
}
/****************************************************************************
 ** \brief	GPIO3_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void GPIO3_IRQHandler(void)
{
	
}
/****************************************************************************
 ** \brief	GPIO4_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void GPIO4_IRQHandler(void)
{
	
}
/****************************************************************************
 ** \brief	CCP_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/

void CCP_IRQHandler(void)
{
	if(CCP_GetCAPMode0IntFlag(CCP1))
	{	
		CCP_ClearCAPMode0IntFlag(CCP1);
		
		//strCom.signal = 0Xffff -CCP_GetCAPMode0Result(CCP1,CCPxB);
		CCP_DisableRun(CCP1);
		CCP_EnableRun(CCP1);
		
#if(HALL_BOARD_EN)		
		
		COM_GetHallLevelCnt(strCom.signal);
		INPUT_GetCutterHallStatus();
		
#endif

		
#if(COM_EN)

		#if(WM_COM_EN)
		COM_RxReceive49bitsFunction();
		#endif
		
		#if(AS_COM_EN)
		COM_RxReceive25bitsFunction();
		#endif
#endif			
		

				
	}
	
	if(CCP_GetOverflowIntFlag(CCP0))
	{
		CCP_ClearOverflowIntFlag(CCP0);		
		//COM_TxSend16bitsFunction();
	}

	
	/*
	if(CCP_GetCAPMode1IntFlag(CAP0))
	{
		GPIO1->DO_f.P3 = ~GPIO1->DO_f.P3;
		CCP_ClearCAPMode1IntFlag(CAP0);	
	}
	if(CCP_GetCAPMode1IntFlag(CAP1))
	{
		CCP_ClearCAPMode1IntFlag(CAP1);		
	}
	if(CCP_GetCAPMode1IntFlag(CAP2))
	{
		CCP_ClearCAPMode1IntFlag(CAP2);			
	}
	*/
	
}
/****************************************************************************
 ** \brief	ADC0_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void ADC0_IRQHandler(void)
{
	
}
/****************************************************************************
 ** \brief	WWDT_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void WWDT_IRQHandler(void)
{
	if(WWDT_GetCompareIntFlag())
	{
		WWDT_ClearCompareIntFlag();
	}		
}
/****************************************************************************
 ** \brief	EPWM_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void EPWM_IRQHandler(void)
{
	if(EPWM_GetPeriodIntFlag(EPWM0))
	{		
		EPWM_ClearPeriodIntFlag(EPWM0);		
	}

	if(EPWM_GetZeroIntFlag(EPWM0))
	{		
		EPWM_ClearZeroIntFlag(EPWM0);		
	}
	NVIC_ClearPendingIRQ(EPWM_IRQn);
}
/****************************************************************************
 ** \brief	ADC1_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void ADC1_IRQHandler(void)  
{
	BSP_ADC1ClearAllChnInt();

	MC_Adc_Isr_Handler();    //<42us
	
	#if(SEND_SCOPE_DATA_EN)
	MU_Send_Scope_Data(1,1,1,1);
	#endif
}
/****************************************************************************
 ** \brief	ACMP_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void ACMP_IRQHandler(void)
{
	if(ACMP_GetIntFlag(ACMP0))
	{
		ACMP_ClearIntFlag(ACMP0);

		#if(SL_CMP_MODE)
		
		MC_Cmp0_Isr_Handler();	
		
		#endif		
		
		//NVIC_ClearPendingIRQ(ACMP0);				
	}
	
	/*
	if(ACMP_GetIntFlag(ACMP1))
	{
		ACMP_ClearIntFlag(ACMP1);
		//NVIC_ClearPendingIRQ(ACMP1);
	}
	*/
	
}
/****************************************************************************
 ** \brief	UART0_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void UART0_IRQHandler(void)
{
	
}
/****************************************************************************
 ** \brief	UART1_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void UART1_IRQHandler(void)
{
	//UARTS_ISRhandler();
}
/****************************************************************************
 ** \brief	TMR0_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void TMR0_IRQHandler(void)
{
	if(TMR_GetOverflowIntFlag(TMR0))
	{
		TMR_ClearOverflowIntFlag(TMR0);
	}	
}
/****************************************************************************
 ** \brief	TMR1_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void TMR1_IRQHandler(void)
{
	if(TMR_GetOverflowIntFlag(TMR1))
	{
		TMR_ClearOverflowIntFlag(TMR1);
		MC_T1_Isr_Handler();			
	}   
}
/****************************************************************************
 ** \brief	WDT_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void WDT_IRQHandler(void)
{
	if(WDT_GetOverflowIntFlag())
	{	
		WDT_ClearOverflowIntFlag();
	}	
}
/****************************************************************************
 ** \brief	I2C_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void I2C_IRQHandler(void)
{
	
}
/****************************************************************************
 ** \brief	SPI_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void SPI_IRQHandler(void)
{
	
}
/****************************************************************************
 ** \brief	GPIO0_IRQHandler
 **
 ** \param [in]  none   
 ** \return none
 ** \note
****************************************************************************/
void LVD_IRQHandler(void)
{	
	if(SYS_GetLVDIntFlag())
	{	
		SYS_ClearLVDIntFlag();
	}	
}



